package rsj.service.product;

import com.rlyy.aibase.utils.base.TableNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import rsj.api.product.entity.Product;
import rsj.sql.product.ProductInfoDao;

import java.util.List;

/**
 * 产品
 *
 * @author yuanqinglong
 * @since 2021/7/16 11:55
 */
@Service
public class ProductServiceImpl implements IProductService {

    @Autowired
    private ProductInfoDao productInfoDao;

    /**
     * 产品类别列表
     *
     * @return {@link List<Product>}
     */
    @Override
    public List<Product> productList() {
        TableNode tableNode = productInfoDao.allProducts();
        return this.classifiedByProductType(tableNode);
    }


    /**
     * 账户的产品
     *
     * @param orgId org id
     * @return {@link List<Product>}
     */
    @Override
    public List<Product> accountConfigurationProducts(String orgId) {
        TableNode tableNode = productInfoDao.accountConfigurationProducts(orgId);
        return this.classifiedByProductType(tableNode);
    }


    /**
     * 更新产品销售
     *
     * @param sales  销售
     * @param prodId 促使id
     */
    @Override
    public void updateProductSales(Integer sales, String prodId) {
        productInfoDao.updateProductSales(sales, prodId);
    }
}
